
import 'package:flutter/cupertino.dart';
import 'package:flutter_member_mvvm/base/api_response.dart';
import 'package:flutter_member_mvvm/logic/model/phone.dart';
import 'package:flutter_member_mvvm/logic/service/login_service.dart';
import 'package:mvvm/mvvm.dart';

class LoginViewModel extends ViewModel with AsyncViewModelMixin {
  final LoginService loginService;
  final TextEditingController phoneCtrl = TextEditingController();

  LoginViewModel(this.loginService) {
    propertyValue<DateTime>(#time, initial: DateTime.now());

    propertyAdaptive<String, TextEditingController>(
        #userName, phoneCtrl, (v) => v.text, (a, v) => a.text = v,
        valueChanged: (v, k) => print("$k: $v"), initial: "");

    propertyAsync<ApiResponse>(
        #login, () => loginService.getVerificationCode(phoneCtrl.text),
        valueChanged: (v, k) => print("$k: $v"));
  }
}